﻿using System;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXing.Common;
using ZXing.QrCode;
using ZXing;
 

namespace Controller
{
    public class QRHFPrinter
    {
        CarrierSignalStatus dd = null;

       static HBase.IMServer MGStatuslog = HBase.GuidangFactray.getDal<HBase.IMServer>();
 
     
        public void print(CarrierSignalStatus ss )
        {
            MGStatuslog.save(ss);
            dd = ss;
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(printEventHandler);
            pd.DefaultPageSettings.PrinterSettings.PrinterName = "ZDesigner ZT610-300dpi ZPL";       //打印机名称
            //pd.DefaultPageSettings.Landscape = true;  //设置横向打印，不设置默认是纵向的
           // pd.DefaultPageSettings.PrinterSettings.PrinterName = "Microsoft Print to PDF";
            pd.PrintController = new StandardPrintController();
            pd.Print();
        }
        private void printEventHandler(object sender, PrintPageEventArgs e) {
            RectangleF imageBounds = e.MarginBounds;
            imageBounds.Width = PngUtil.width;
            imageBounds.Height = PngUtil.high;

         
            PngUtil. drawLine(e.Graphics);
            PngUtil.drawStatic(e.Graphics);
            drawAuto(e.Graphics, PngUtil.width, PngUtil.qrSize, PngUtil.marginTop, PngUtil.gap, PngUtil.brush, PngUtil.marginLeft, PngUtil.contentWidth, PngUtil.gapTop, PngUtil.f);

           


        }

        public void save(CarrierSignalStatus ss)
        {
            Bitmap bmp = new Bitmap(PngUtil.width, PngUtil. high);
            Graphics g = Graphics.FromImage(bmp);
            dd = ss;

            PngUtil.drawLine(g);
            PngUtil.drawStatic(g);
            drawAuto(g, PngUtil.width, PngUtil.qrSize, PngUtil.marginTop, PngUtil.gap, PngUtil.brush, PngUtil.marginLeft, PngUtil.contentWidth, PngUtil.gapTop, PngUtil.f);
            bmp.Save("aaab.png");
      
            bmp.Dispose();
        }

       
        void drawAuto(Graphics g,int width,int qrSize,int marginTop,int gap,Brush brush,int marginLeft,int contentWidth,int gapTop, Font f) {
            g.DrawImage(PngUtil.CreateQRCode(dd.code), width / 2 - qrSize / 2, marginTop + 7 * gap);
            PngUtil.ds(g, dd.code, new Font("宋体", 14, FontStyle.Regular), brush, width / 2, marginTop + gap * 9 - 20); 
            PngUtil. ds(g, dd.gg, f, brush, marginLeft + contentWidth * 3 / 4, marginTop + gap * 2 + gapTop, "specification");
            PngUtil.ds(g, dd.type, f, brush, marginLeft + contentWidth / 4, marginTop + gap * 4 + gapTop, "type");
            PngUtil.ds(g, dd.lotNo, f, brush, marginLeft + contentWidth * 3 / 4, marginTop + gap * 4 + gapTop, "lotNo");
            PngUtil.ds(g, dd.mz, f, brush, marginLeft + contentWidth / 6, marginTop + gap * 6 + gapTop, "grossWt");
            PngUtil.ds(g, dd.jz, f, brush, marginLeft + contentWidth * 3 / 6, marginTop + gap * 6 + gapTop, "netWt");
            PngUtil.ds(g, dd.roll, f, brush, marginLeft + contentWidth * 5 / 6, marginTop + gap * 6 + gapTop, "roll"); 
        } 
        /// 二维码方法
       
    }
}
